using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Terra.Core.Common.Models.Base;
using Terra.Core.Common.Models.Common;
using Terra.Core.Common.Models.Pagination;

namespace Terra.Data.Models.Identity;

/// <summary>
/// 菜单完整DTO - 所有菜单相关DTO的基类
/// </summary>
public class MenuBaseDto
{


    /// <summary>
    /// 菜单名称
    /// </summary>
    [Required(ErrorMessage = "菜单名称不能为空")]
    [StringLength(30, ErrorMessage = "菜单名称长度不能超过30个字符")]
    public string Name { get; set; }

    /// <summary>
    /// 菜单类型：menu-菜单，catalog-目录，button-按钮，embedded-内嵌，link-外链
    /// </summary>
    [Required(ErrorMessage = "菜单类型不能为空")]
    [StringLength(20, ErrorMessage = "菜单类型长度不能超过20个字符")]
    public string Type { get; set; } = "menu";

    /// <summary>
    /// 路由路径
    /// </summary>
    [StringLength(100, ErrorMessage = "路由路径长度不能超过100个字符")]
    public string Path { get; set; }

    /// <summary>
    /// 激活路径
    /// </summary>
    [StringLength(100, ErrorMessage = "激活路径长度不能超过100个字符")]
    public string ActivePath { get; set; }

    /// <summary>
    /// 组件路径
    /// </summary>
    [StringLength(100, ErrorMessage = "组件路径长度不能超过100个字符")]
    public string Component { get; set; }

    /// <summary>
    /// 外链地址
    /// </summary>
    [StringLength(255, ErrorMessage = "外链地址长度不能超过255个字符")]
    public string LinkSrc { get; set; }

    /// <summary>
    /// 权限编码
    /// </summary>
    [StringLength(100, ErrorMessage = "权限编码长度不能超过100个字符")]
    public string AuthCode { get; set; }

    /// <summary>
    /// 菜单状态：1-启用，0-禁用
    /// </summary>
    public int Status { get; set; } = 1;

    /// <summary>
    /// 父级Id
    /// </summary>
    public Guid? ParentId { get; set; }

    /// <summary>
    /// 排序号
    /// </summary>
    public int Sort { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedTime { get; set; }

    /// <summary>
    /// 最后修改时间
    /// </summary>
    public DateTime? LastModifiedTime { get; set; }

    /// <summary>
    /// 元数据
    /// </summary>
    public MenuMetaDto Meta { get; set; }
}

/// <summary>
/// 菜单基础DTO - 用于简单场景
/// </summary>
public class MenuDto : MenuBaseDto
{
}

/// <summary>
/// 菜单树形DTO
/// </summary>
public class MenuTreeDto : MenuBaseDto
{

    /// <summary>
    /// 菜单ID
    /// </summary>
    public Guid Id { get; set; }
    /// <summary>
    /// 层级
    /// </summary>
    public int Level { get; set; }

    /// <summary>
    /// 是否为叶子节点
    /// </summary>
    public bool IsLeaf { get; set; }

    /// <summary>
    /// 附加数据
    /// </summary>
    public object Data { get; set; }

    /// <summary>
    /// 子节点
    /// </summary>
    public List<MenuTreeDto> Children { get; set; } = new List<MenuTreeDto>();

    /// <summary>
    /// 权限ID
    /// </summary>
    public Guid? PermissionId { get; set; }
}

/// <summary>
/// 菜单元数据DTO
/// </summary>
public class MenuMetaDto
{
    /// <summary>
    /// 菜单标题（国际化键）
    /// </summary>
    [Required(ErrorMessage = "菜单标题不能为空")]
    [StringLength(100, ErrorMessage = "菜单标题长度不能超过100个字符")]
    public string Title { get; set; }

    /// <summary>
    /// 图标
    /// </summary>
    [StringLength(50, ErrorMessage = "图标长度不能超过50个字符")]
    public string Icon { get; set; }

    /// <summary>
    /// 激活图标
    /// </summary>
    [StringLength(50, ErrorMessage = "激活图标长度不能超过50个字符")]
    public string ActiveIcon { get; set; }

    /// <summary>
    /// 是否缓存标签页
    /// </summary>
    public bool KeepAlive { get; set; }

    /// <summary>
    /// 是否固定在标签页
    /// </summary>
    public bool AffixTab { get; set; }

    /// <summary>
    /// 在菜单中隐藏
    /// </summary>
    public bool HideInMenu { get; set; }

    /// <summary>
    /// 隐藏子菜单
    /// </summary>
    public bool HideChildrenInMenu { get; set; }

    /// <summary>
    /// 在面包屑中隐藏
    /// </summary>
    public bool HideInBreadcrumb { get; set; }

    /// <summary>
    /// 在标签栏中隐藏
    /// </summary>
    public bool HideInTab { get; set; }

    /// <summary>
    /// 徽章类型：dot-圆点，normal-文本
    /// </summary>
    [StringLength(20, ErrorMessage = "徽章类型长度不能超过20个字符")]
    public string BadgeType { get; set; }

    /// <summary>
    /// 徽章内容
    /// </summary>
    [StringLength(30, ErrorMessage = "徽章内容长度不能超过30个字符")]
    public string Badge { get; set; }

    /// <summary>
    /// 徽章样式
    /// </summary>
    [StringLength(50, ErrorMessage = "徽章样式长度不能超过50个字符")]
    public string BadgeVariants { get; set; }

    /// <summary>
    /// 内嵌链接地址
    /// </summary>
    public string IframeSrc { get; set; }

    /// <summary>
    /// 外部链接地址
    /// </summary>
    public string Link { get; set; }
}

/// <summary>
/// 菜单查询DTO
/// </summary>
public class MenuQueryDto : PagedRequest
{
    /// <summary>
    /// 菜单名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 菜单类型
    /// </summary>
    public string Type { get; set; }

    /// <summary>
    /// 菜单状态
    /// </summary>
    public int? Status { get; set; }
}

/// <summary>
/// 菜单创建DTO
/// </summary>
public class MenuCreateDto : MenuBaseDto
{

}

/// <summary>
/// 菜单更新DTO
/// </summary>
public class MenuUpdateDto : MenuCreateDto
{
    /// <summary>
    /// 菜单ID
    /// </summary>
    [Required(ErrorMessage = "菜单ID不能为空")]
    public Guid Id { get; set; }
}

/// <summary>
/// 菜单详情DTO
/// </summary>
public class MenuDetailDto : MenuBaseDto
{
    /// <summary>
    /// 菜单ID
    /// </summary>
    public Guid Id { get; set; }
}

/// <summary>
/// 菜单列表项DTO
/// </summary>
public class MenuItemDto : MenuBaseDto
{
    /// <summary>
    /// 菜单ID
    /// </summary>
    public Guid Id { get; set; }
    /// <summary>
    /// 父菜单名称
    /// </summary>
    public string ParentName { get; set; }
}

/// <summary>
/// 菜单选择DTO
/// </summary>
public class MenuSelectDto
{
    /// <summary>
    /// 菜单ID
    /// </summary>
    public Guid Id { get; set; }

    /// <summary>
    /// 菜单名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 菜单标题
    /// </summary>
    public string Title { get; set; }
}

/// <summary>
/// 前端路由菜单DTO
/// </summary>
public class RouterMenuDto
{
    /// <summary>
    /// 菜单名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 路由路径
    /// </summary>
    public string Path { get; set; }

    /// <summary>
    /// 组件路径
    /// </summary>
    public string Component { get; set; }

    /// <summary>
    /// 重定向地址
    /// </summary>
    public string Redirect { get; set; }

    /// <summary>
    /// 元数据
    /// </summary>
    public MenuMetaDto Meta { get; set; }

    /// <summary>
    /// 子菜单
    /// </summary>
    public List<RouterMenuDto> Children { get; set; }
}
